/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package de.hsmannheim.pepa.patientenportal.apanwep.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import de.hsmannheim.pepa.patientenportal.apanwep.service.ClpSerializer;
import de.hsmannheim.pepa.patientenportal.apanwep.service.messages_mparticipantsLocalServiceUtil;
import de.hsmannheim.pepa.patientenportal.apanwep.service.persistence.messages_mparticipantsPK;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cedric Nana
 */
public class messages_mparticipantsClp extends BaseModelImpl<messages_mparticipants>
	implements messages_mparticipants {
	public messages_mparticipantsClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return messages_mparticipants.class;
	}

	@Override
	public String getModelClassName() {
		return messages_mparticipants.class.getName();
	}

	@Override
	public messages_mparticipantsPK getPrimaryKey() {
		return new messages_mparticipantsPK(_messages_id,
			_messageparticipants_id);
	}

	@Override
	public void setPrimaryKey(messages_mparticipantsPK primaryKey) {
		setMessages_id(primaryKey.messages_id);
		setMessageparticipants_id(primaryKey.messageparticipants_id);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return new messages_mparticipantsPK(_messages_id,
			_messageparticipants_id);
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey((messages_mparticipantsPK)primaryKeyObj);
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("messages_id", getMessages_id());
		attributes.put("messageparticipants_id", getMessageparticipants_id());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long messages_id = (Long)attributes.get("messages_id");

		if (messages_id != null) {
			setMessages_id(messages_id);
		}

		Long messageparticipants_id = (Long)attributes.get(
				"messageparticipants_id");

		if (messageparticipants_id != null) {
			setMessageparticipants_id(messageparticipants_id);
		}
	}

	@Override
	public long getMessages_id() {
		return _messages_id;
	}

	@Override
	public void setMessages_id(long messages_id) {
		_messages_id = messages_id;

		if (_messages_mparticipantsRemoteModel != null) {
			try {
				Class<?> clazz = _messages_mparticipantsRemoteModel.getClass();

				Method method = clazz.getMethod("setMessages_id", long.class);

				method.invoke(_messages_mparticipantsRemoteModel, messages_id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getMessageparticipants_id() {
		return _messageparticipants_id;
	}

	@Override
	public void setMessageparticipants_id(long messageparticipants_id) {
		_messageparticipants_id = messageparticipants_id;

		if (_messages_mparticipantsRemoteModel != null) {
			try {
				Class<?> clazz = _messages_mparticipantsRemoteModel.getClass();

				Method method = clazz.getMethod("setMessageparticipants_id",
						long.class);

				method.invoke(_messages_mparticipantsRemoteModel,
					messageparticipants_id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getmessages_mparticipantsRemoteModel() {
		return _messages_mparticipantsRemoteModel;
	}

	public void setmessages_mparticipantsRemoteModel(
		BaseModel<?> messages_mparticipantsRemoteModel) {
		_messages_mparticipantsRemoteModel = messages_mparticipantsRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _messages_mparticipantsRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_messages_mparticipantsRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			messages_mparticipantsLocalServiceUtil.addmessages_mparticipants(this);
		}
		else {
			messages_mparticipantsLocalServiceUtil.updatemessages_mparticipants(this);
		}
	}

	@Override
	public messages_mparticipants toEscapedModel() {
		return (messages_mparticipants)ProxyUtil.newProxyInstance(messages_mparticipants.class.getClassLoader(),
			new Class[] { messages_mparticipants.class },
			new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		messages_mparticipantsClp clone = new messages_mparticipantsClp();

		clone.setMessages_id(getMessages_id());
		clone.setMessageparticipants_id(getMessageparticipants_id());

		return clone;
	}

	@Override
	public int compareTo(messages_mparticipants messages_mparticipants) {
		messages_mparticipantsPK primaryKey = messages_mparticipants.getPrimaryKey();

		return getPrimaryKey().compareTo(primaryKey);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof messages_mparticipantsClp)) {
			return false;
		}

		messages_mparticipantsClp messages_mparticipants = (messages_mparticipantsClp)obj;

		messages_mparticipantsPK primaryKey = messages_mparticipants.getPrimaryKey();

		if (getPrimaryKey().equals(primaryKey)) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return getPrimaryKey().hashCode();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(5);

		sb.append("{messages_id=");
		sb.append(getMessages_id());
		sb.append(", messageparticipants_id=");
		sb.append(getMessageparticipants_id());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(10);

		sb.append("<model><model-name>");
		sb.append(
			"de.hsmannheim.pepa.patientenportal.apanwep.model.messages_mparticipants");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>messages_id</column-name><column-value><![CDATA[");
		sb.append(getMessages_id());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>messageparticipants_id</column-name><column-value><![CDATA[");
		sb.append(getMessageparticipants_id());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _messages_id;
	private long _messageparticipants_id;
	private BaseModel<?> _messages_mparticipantsRemoteModel;
}